<?php
namespace app\gongzhong\controller;
use think\Controller;
use think\Db;

use app\lib\aliyun\Api as aliyunApi;
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;

class Base extends Controller
{
    public $exception = [];

    public function __construct(){
        parent::__construct();

        $login_user = session("login_openid");
        $action = strtolower(request()->action());
        $exception = array_map('strtolower',$this->exception);
        if(empty($login_user) && !in_array($action, $exception)){
            $this->redirect(url('index/login'));
        }
        $this->login_user = $login_user;

        $this->assign([
            'login_user'=>$login_user,
        ]);
    }


    

    /**
     * 上传图片
     * @Author   CCH
     * @DateTime 2020-08-15T17:26:24+0800
     * @return   [type]                   [description]
     */
    // public function upload(){
    //     $file = $_FILES['file'];
    //     if (empty($file)) {
    //         return json(['code'=>5000,'msg'=>'未检测到图片']);
    //     }
    //     $ext = explode(".", $file['name']);//拆分获取图片名
    //     $ext = $ext[count($ext) - 1];//取图片的后缀名
    //     $ext = strtolower($ext);
    //     $types = ["jpg", "gif", 'png', 'bmp','jpeg'];
    //     if (!in_array($ext, $types)) {
    //         return json(['code'=>5000,'msg'=>'文件格式不支持，请上传标准图片文件']);
    //     }
    //     $result = uploadFile($file['name'],$file['tmp_name'],date('Ymd').'/');

    //     if ($result['status'] == 1) {
    //         $result = [
    //             'code'=>2000,'msg'=>'上传成功：'.$file['name'],
    //             'extension'=>$ext,
    //             'savename'=>$result['data'],
    //             'filename'=>$file['name']
    //         ];
    //         return json($result);
    //     }else{
    //         return json(['code'=>5000,'msg'=>$result['msg']]);
    //     }
    // }


}
